/**
 * 1.本代码为云笔记web端开发小组共同拥有。
 * 2.组内成员有 聂道鑫、徐斌强、何瑞、钟倩。
 * 3.联系方式：442342707@qq.com
 */
package com.yunbiji.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
/**
 * 成员文件夹类
 * @author 聂道鑫
 *
 */
@SuppressWarnings("serial")
public class Member_folders extends Model<Member_folders>
{
	public static final Member_folders dao=new Member_folders();
	
	private String getMemberFoldersSql = "select * from member_folders where tel =? and h_fafolder =?";
	
	private String ifDeleteMemberFoldersSql="select count(*) as counts from member_folders where h_fafolder = ?";

	
	/**
	 * 获取成员组
	 * @param tel
	 * @param pIdString
	 * @return
	 */
	public List<Member_folders> getMemberFolders(String tel, String pIdString)
	{
		int pId=Integer.valueOf(pIdString);
		List<Member_folders> list;

		list = Member_folders.dao.find(getMemberFoldersSql, tel,pId);

		return list;
	}
	/**
	 * 删除文件夹
	 * @author niedaoxin
	 * @param idString
	 * @return boolean
	 */
	public boolean deleteMemberFolders(String idString)
	{
		//这里采用的jfinal独有的db+record模式的查询
		int id=Integer.valueOf(idString);
		Record record = Db.findFirst(ifDeleteMemberFoldersSql, id);
		Long counts = record.getNumber("counts").longValue();
		if(counts>0)
		{
			return false;
		}
		else
		{
			Member_folders.dao.deleteById(id);
			return true;
		}
	}
	/**
	 * 返回获取的文件夹名字
	 * @param pId
	 * @return String
	 */
	public String queryStrName(String pId)
	{
		return (Db.queryStr("SELECT h_name From member_folders WHERE id=?",Integer.valueOf(pId)));
	}
	/**
	 * 返回获取的文件夹名字
	 * @param pId
	 * @param tel
	 * @return
	 */
	public String queryStrName(String pId,String tel)
	{
		return (Db.queryStr("SELECT h_name From member_folders WHERE id=? and tel=?",Integer.valueOf(pId),tel));
	}
}
